//*************************************************************************
//  UART Header Datei fuer ATMega644
//  -Original von Peter Fleury-
//
//  contact: sebastian.trommer@gmail.com
//  homepage: wiki.car2.de
//
//  Revision History
//
//  when         what  who	why
//
//  2009-01-05   1.00  TSE	initial release
//  2009-01-07	 1.01  TSE  aufbau der RDS-Takt Routinen
//
//**************************************************************************
#ifndef UART_H
#define UART_H

// Konstanten und Macros
#define UART_BAUD_SELECT(baudRate,xtalCpu) ((xtalCpu)/((baudRate)*16l)-1)
#define UART_BAUD_SELECT_DOUBLE_SPEED(baudRate,xtalCpu) (((xtalCpu)/((baudRate)*8l)-1)|0x8000)

// Groesse des Empfangspuffers, 2er Potenz
#ifndef UART_RX_BUFFER_SIZE
#define UART_RX_BUFFER_SIZE 32
#endif
// Groesse des Sendepuffers, 2er Potenz
#ifndef UART_TX_BUFFER_SIZE
#define UART_TX_BUFFER_SIZE 32
#endif

// Passen die Puffer ins RAM
#if ( (UART_RX_BUFFER_SIZE+UART_TX_BUFFER_SIZE) >= (RAMEND-0x60 ) )
#error "size of UART_RX_BUFFER_SIZE + UART_TX_BUFFER_SIZE larger than size of SRAM"
#endif

// error return codes von uart_getc()
#define UART_FRAME_ERROR      0x0800              /* Framing Error by UART       */
#define UART_OVERRUN_ERROR    0x0400              /* Overrun condition by UART   */
#define UART_BUFFER_OVERFLOW  0x0200              /* receive ringbuffer overflow */
#define UART_NO_DATA          0x0100              /* no receive data available   */

// Funktionsprototypen
extern void UART_init(unsigned int baudrate);
extern unsigned int UART_getc(void);
extern void UART_putc(unsigned char data);
extern void UART_puts(unsigned char *s );
extern void UART_puts_p(const char *s );

#define UART_puts_P(__s) UART_puts_p(PSTR(__s))

#endif
